<?php
	
require_once("database.php");
$id = $_GET['id'];
$foreignKey = $_GET['foreignKey'];
$bodyString = "";
if ($id) {
	$SQLreadQuery = "SELECT * FROM best_videos WHERE id = $id";
	$SQLreadResult = $db->query($SQLreadQuery);
	while ($rowArray = $db->fetch_array($SQLreadResult)) {
		$sort_order = $rowArray["sort_order"];
		$title = $rowArray["title"];
		$height = $rowArray["height"];
		$width = $rowArray["width"];
		$videoFile = $rowArray["videoFile"];
		$extraInfo = $rowArray["extraInfo"];
		$id = $rowArray["id"];
	}						
}

require_once('io_library.php');
if (session_id() != "") {
	//session_start(); 
	//echo "starting a new session now";
}
session_start();
if ($_GET['sessionDepth'] && $_SERVER['HTTP_REFERER']) { // if it needs a ref URL and they have SERVER data
	$sessionDepth =  'depth' . $_GET['sessionDepth'];
	if (!$_SESSION[$_GET['sessionDepth']] || $_SESSION[$sessionDepth] == "") {
		//session_register($sessionDepth);
		$_SESSION[$sessionDepth] = $_SERVER['HTTP_REFERER'];
	}
	$referringPage = $_SESSION[$sessionDepth]; // then give 'em what DEY need
}
//print_r($_SESSION);
	
if (!$referringPage)						// else send to parent 'list' page							
	$referringPage = "best_videos_list.php";
?>
<html>
	<head>
		<title>TheBest.com > Videos</title>
		<?php require_once('io_writePage_includes.php'); ?>
	<script type='text/javascript'>
		var refererURL = '<?php echo $referringPage; ?>';
		var parent_id = '<?php echo $id; ?>';
		var parent_table = 'best_videos';
	</script>
	</head>
	<body>
	<div class='navigation'>
	  <div id='goTo'>Menu...</div>
	  <div id="tableList">
    <?php
    $currentNavTable = 'best_videos';
    require_once('navlist.php');
    ?>
    </div> <!-- end #tableList -->
	  <div class='siteName'>TheBest.com</div><div id='currentTableTitle'><a href='best_videos_list.php'>Videos</a></div>
	</div> <!-- end .navigation -->
	<div id="fieldsList">
		<form id='best_videosForm' method="post" action="<?php echo $referringPage; ?>"><?php echo "<input class='formElement' type='hidden' name='sort_order' value='$sort_order' />";
		// Entry Method Type : {textField}
		echo "<label for='title'>Title</label><input type='text' name='title' size='100' class='formElement best_videosInput' value='$title'>";
		// Entry Method Type : {textField}
		echo "<label for='height'>Video Height (pixels)</label><input type='text' name='height' size='100' class='formElement best_videosInput' value='$height'>";
		// Entry Method Type : {textField}
		echo "<label for='width'>Video Width (pixels)</label><input type='text' name='width' size='100' class='formElement best_videosInput' value='$width'>";
		// Entry Method Type : {fileUpload}
if ($id) {
	echo "<div id='".$id."videoFile' class='noCrop'>
				<label for='videoFile'>Video File</label>".fileUploadDisplay($videoFile)."";
	echo "<input type='file' name='videoFile' class='fileUpload' value='$videoFile' id='".$id."'/><div class='originalFile'><input type='hidden' name='videoFile' value='$videoFile' /></div></div>";	
}
else {
	echo "<div id='new_item_videoFile'  class='noCrop'><label for='videoFile'>Video File</label><div class='new'></div>";
	echo "<input type='file' name='videoFile' class='fileUpload' value='$videoFile' /><div class='originalFile'><input type='hidden' name='videoFile' value='$videoFile' /></div></div>";	
}
		// Entry Method Type : {textArea}
		echo "<label for='extraInfo'>Credits / Extra Info</label><textarea name='extraInfo' cols='40' rows='6' class='formElement best_videosInput'>$extraInfo</textarea>"; ?>
		<input type="hidden" name="id" value="<?php echo $_GET['id'];?>" />
		<?php 
		if ($_GET['linkedChild']) {
			echo "<input type='hidden' name='linkedChild' value='".$_GET['linkedChild']."' />";
		}
		?>
		<input type="hidden" name="TABLENAME" value="best_videos" />
		<input type="submit" value="Save" id='saveRecord' />
		</form>
		<input type="submit" value="Cancel" id='cancelRecord' />
	</div>
	</body>
</html>